﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;
using Microsoft.Practices.Prism.Regions;
using DeveloperModule.Views;
using DeveloperModule.ViewModels;
using DeveloperModule.Services;

namespace DeveloperModule.Views
{
    /// <summary>
    /// Interaction logic for UserSelectionView.xaml
    /// </summary>
    public partial class UserSelectionView : UserControl, INavigationAware
    {
        private UserSelectionViewModel Model;
        private readonly IDeveloperService _developerService;

        public UserSelectionView(IDeveloperService developerService)
        {
            InitializeComponent();

            _developerService = developerService;
        }

        public bool IsNavigationTarget(NavigationContext navigationContext)
        {
            return false; //throw new NotImplementedException();
        }

        public void OnNavigatedFrom(NavigationContext navigationContext)
        {
            //throw new NotImplementedException();
        }

        public async void OnNavigatedTo(NavigationContext navigationContext)
        {
            // TODO:
            await Task.Run(() => Model = _developerService.GetUserSelectionViewModel());

            this.DataContext = Model;
        }

        private async void changeButton_Click(object sender, RoutedEventArgs e)
        {
            this.changeButton.IsEnabled = false;

            await Task.Run(() => _developerService.ChangeSessionUser(Model.SelectedUser));

            this.changeButton.IsEnabled = true;
        }

        private async void fixButton_Click(object sender, RoutedEventArgs e)
        {
            this.fixButton.IsEnabled = false;

           // await Task.Run(() => _developerService.FixTaskStartedDate());
           // await Task.Run(() => _developerService.FixTaskCompletedDate());

            await Task.Run(() => _developerService.UpdateActualHoursForProjectsAndTasks());

            this.fixButton.IsEnabled = true;
        }

        // need method that changes the session user, need to create the combo box
    }
}
